from selenium.webdriver.common.action_chains import ActionChains

from selenium import webdriver

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.common.by import By

import time




option = webdriver.ChromeOptions()
option.add_argument("--start-maximized")
option.add_argument('--no-sandbox')

browser = webdriver.Chrome(chrome_options=option)

wait=WebDriverWait(browser,10)

actions=ActionChains(browser)

url='https://www.lepu.cn/'

app_icon=(By.CSS_SELECTOR,'.currentCity')
browser.get(url)
currentCity=wait.until(EC.presence_of_element_located(app_icon))


ActionChains(browser).move_to_element(currentCity)
currentCity.click()

# allCity=wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR,'.allCity>li:nth-last-child(1)')))
#
# allCity.click()

js = "window.open('https://www.baidu.com/');"  # 新窗口打开链接

browser.execute_script(js)

time.sleep(2)
#
browser.switch_to.window(browser.window_handles[1])
time.sleep(5)
browser.close()



















